package hot100;

public class searchMatrix {
    public boolean searchMatrix(int[][] matrix, int target) {
        int row = matrix.length;//行
        int col = matrix[0].length-1;//列
        //判断每行第n列的元素 == tar return true; < tar 换行;> tar 进行二分
        for(int i = 0;i < row;i++) {
            if(matrix[i][col] ==target) {
                return true;
            }else if(matrix[i][col] < target) {

            }else {
                int left = 0;
                int right = col;
                int mid = 0;
                while(left <= right) {
                    mid = left+(right-left)/2;
                    if(matrix[i][mid] == target) {
                        return true;
                    }else if(matrix[i][mid] < target) {
                        left = mid+1;
                    }else {
                        right = mid-1;
                    }

                }
            }
        }
        return false;

    }
}
